<?php
/* How To Use
 * $this->String_Helper = new String_Helper;
 * $this->String_Helper->code_string($str)
 * Coder By Mirage
 */
Class String_Helper {
    function code_string($str){
        $end = 0;
        $last = 0;
        $start_point = array();
        $break_point = array();
        $output = '';
        while($start = strpos ( $str, '[code]', $end  )){
            if(!$end = strpos ( $str, '[/code]', $start  )){
                break;
            }
            $start_point[] = $start;
            $break_point[] = $end;
            $buffer .= substr($str,$last,$start-$last).nl2br(htmlspecialchars(substr($str,$start+6,$end-$start-6)));
            $last = $end + 7;
        }
        $buffer .= substr($str,$last);
        return $buffer;
    }
	
	function substr_utf8( $str, $start_p , $len_p){  
	 return preg_replace( '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start_p.'}'.  
	  '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len_p.'}).*#s',  
	  '$1' , $str);  
	}
	
	function substr_utf8_folder( $str, $start_p , $len_p){  
	 return preg_replace( '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start_p.'}'.  
	  '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len_p.'}).*#s',  
	  '$1' , $str."..." );  
	}
	
}
?>